<?php

$PHPSESSID = @$_GET['PHPSESSID'];
$CheckLevel = @$_GET['CheckLevel'];
$RefTable = @$_GET['RefTable'];
$lower = @$_GET['lower'];

if(!strlen($lower)>0) {
    $lower = 0;
}
/*
 *
echo '<pre>';
print_r($_POST);
echo '</pre>';
*/

echo '<div id="page_header">'."\n";
echo '<ul>'."\n";
echo '<li class="titlename2">Reference Data</li>'."\n";
echo '</ul>'."\n";
echo '</div>'."\n";


$base_page_name = "index.php?view=RefData_All";

echo '<div id="details-section">'."\n";
echo '<div id="RefDataDetailsC1">'."\n";



$dir = "_content/_ReferenceData";
$count =0;
$opened_file = opendir($dir);
while ( $file = readdir($opened_file) ) {
    if ( $file != "." && $file != ".." && substr($file, strlen($file)-4, 4) == ".php") {
        if (strpos(" ".$file, "phpMyEdit")>0){
            continue;
        }
        //add to array.
        $fileList[] = substr($file,0, strlen($file)-4);
    }
}
sort($fileList);
foreach ($fileList as $filename) {

    if ($count==0){
        echo '<ul class="RefDataOverview">'."\n";
    }

    if (($count % 3)==0 && $count!=0)
    {
        echo '</ul>'."\n";
        echo '<ul class="RefDataOverview">'."\n";

    }
    //build php page to get image for report.
    //if images does not exist, use default image

    echo '<li class="colw33pc">'."\n";
    echo '<a href="'.$base_page_name.'&amp;RefTable='.$filename.'" >'."\n";
    echo $filename."\n";
    echo '</a>'."\n";
    echo '</li>'."\n";


    $count++;
    //      }
}
if ($count > 0){
    echo '</ul>'."\n";

}

closedir($opened_file);

echo '</div>'."\n";
echo '</div>'."\n";

/*


echo '<table border="0" cellpadding="1" width="100%"><tr>';

echo '<td ><a href="'.$base_page_name.'RefTable=ChurchDepartureReason">ChurchDepartureReason</a></td>';
echo '<td><a href="'.$base_page_name.'RefTable=Agerange">Agerange</a></td>';
echo '<td><a href="'.$base_page_name.'RefTable=Gender">Gender</a></td>';
echo '</tr><tr>';

echo '<td><a href="'.$base_page_name.'RefTable=ChurchIntroductionMethod">ChurchIntroductionMethod</a></td>';
echo '<td><a href="'.$base_page_name.'RefTable=MetaData">MetaData</a></td>';
echo '<td><a href="'.$base_page_name.'RefTable=PremiseType">PremiseType</a></td>';
echo '</tr><tr>';

echo '<td><a href="'.$base_page_name.'RefTable=EducationalInstitution">EducationalInstitution</a></td>';
echo '<td><a href="'.$base_page_name.'RefTable=Worktype">Worktype</a></td>';
echo '<td><a href="'.$base_page_name.'RefTable=Postcode">Postcode</a></td>';
echo '</tr><tr>';

echo '<td><a href="'.$base_page_name.'RefTable=EducationGrade">EducationGrade</a></td>';
echo '<td><a href="'.$base_page_name.'RefTable=MaritalStatus">MaritalStatus</a></td>';
echo '<td><a href="'.$base_page_name.'RefTable=PostcodeSuburbMapping">PostcodeSuburbMapping</a></td>';

echo '</tr><tr>';
echo '<td><a href="'.$base_page_name.'RefTable=BookletFooterMessage">BookletFooterMessage</a></td>';
echo '<td><a href="'.$base_page_name.'RefTable=RoleType">RoleType</a></td>';
echo '<td><a href="'.$base_page_name.'RefTable=Suburb">Suburb</a></td>';
echo '</tr><tr>';

echo '<td></td><td><a href="'.$base_page_name.'RefTable=Title">Title</a></td>';
echo '<td><a href="'.$base_page_name.'RefTable=State">State</a></td>';
echo '</tr><tr>';

echo '<td></td><td></td><td><a href="'.$base_page_name.'RefTable=StreetType">StreetType</a></td>';
echo '</tr></table>';
*/


if(strlen($RefTable)>0) {
    // set defaults for phpMyEdit class

    $opts['RefTable'] = $RefTable;

    $opts['hn'] = $PACTS_cfg->dbserver;// user name
    $opts['un'] = $PACTS_cfg->dbuser;// user name
    $opts['pw'] = $PACTS_cfg->dbpass;//password
    $opts['db'] = $PACTS_cfg->dbname;//database
    $opts['url']['images'] = 'furniture/design/phpMyEditimages/';
    $opts['page_name'] = $base_page_name.'&RefTable='.$RefTable;

    // Options you wish to give the users
    // A - add,  C - change, P - copy, V - view, D - delete,
    // F - filter, I - initial sort suppressed
    $opts['options'] = 'ACPVDF';
    // Navigation style: B - buttons (default), T - text links, G - graphic links
    // Buttons position: U - up, D - down (default)
    $opts['navigation'] = 'GU';
    // Display special page elements
    $opts['display'] = array(
    'form'  => true,
    'query' => true,
    'sort'  => true,
    'time'  => false,
    'tabs'  => true
    );
    // Set default prefixes for variables
    $opts['js']['prefix']               = 'PME_js_';
    $opts['dhtml']['prefix']            = 'PME_dhtml_';
    $opts['cgi']['prefix']['operation'] = 'PME_op_';
    $opts['cgi']['prefix']['sys']       = 'PME_sys_';
    $opts['cgi']['prefix']['data']      = 'PME_data_';

/* Get the user's default language and use it if possible or you can
   specify particular one you want to use. Refer to official documentation
   for list of available languages. */
    $opts['language'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'] . '-UTF8';
    // Number of records to display on the screen
    // Value of -1 lists all records in a table
    $opts['inc'] = 15;


    // Number of lines to display on multiple selection filters
    $opts['multiple'] = '4';


    echo '<div class="phpMyEdit-section">'."\n";
    echo '<p class="titlename1">Maintain '.$RefTable.' Reference Data</p>'."\n";
    // now build the reference table
    include("_content/_ReferenceData/".$RefTable.".php");

    echo '</div>'."\n";

}// end if any content
//echo '</div>'."\n";
?>
